$(function(){
    // 选项卡部分
    $("#zh").click(function(){
        $("#dlzc-zhdl").css("display","block");
        $("#dlzc-aqdl").css("display","none");
        $("#dlzc-sjdl").css("display","none");
    })
    $("#aq").click(function(){
        $("#dlzc-zhdl").css("display","none");
        $("#dlzc-aqdl").css("display","block");
        $("#dlzc-sjdl").css("display","none");
    })
    $("#change").click(function(){
        $("#dlzc-zhdl").css("display","none");
        $("#dlzc-aqdl").css("display","none");
        $("#dlzc-sjdl").css("display","block");
        $("#change1").css("display","block");
    })
    $("#change1").click(function(){
        $("#dlzc-zhdl").css("display","none");
        $("#dlzc-sjdl").css("display","none");
        $("#dlzc-aqdl").css("display","block");
        $("#saoma").css("display","block");
        $("#change1").css("display","none");
    })


    $("#dlzc-aqdl").mouseover(function(){
        $("#saoma").css("display","block");
    })
    $("#dlzc-aqdl").mouseout(function(){
        $("#saoma").css("display","none");
    })

    // 登录注册
    var x = document.cookie;
    // console.log(x);
    $("#dlzc-zhdl>button").click(function(){
        // var a=$("#dlsj").val();
        // var b=$("#qsrmm").val();
        var c=`${$("#dlsj").val()}=${$("#qsrmm").val()}`
        // console.log(c);
        var d=document.cookie.split("; ");
        // console.log(d);
        for(var i=0;i<d.length;i++){
            // console.log(d[i]);
            // console.log(c);
            if(d[i]==c){
                console.log("对了");
                $("#dlzc-zhdl").css("display","none");
                $("#dlzc-title").css("display","none");
                $("#cgdl").css("display","block")
            }
        }
    })

    // 主页左侧
    $("#lefts").on("mouseover","li",function(){
        // console.log(this);
        $(this).addClass("show").siblings().removeClass("show");
    })
    $("#lefts").on("mouseout","li",function(){
        // console.log(this);
        $(this).removeClass("show");
    })

    // 关闭点击查看
    $(".icon-cuo").click(function(){
        $(".weidu").remove();
    })

    // 文章加载
    // var getOffset = {
    //     left:function(obj){
    //         return obj.offsetLeft + (obj.offsetParent ? this.left(obj.offsetParent) : 0);
    //     },
    //     top:function(){
    //         return obj.offsetTop + (obj.offsetParent ? this.top(obj.offsetParent) : 0);
    //     }
    // };
    // 先加载指定个数的文章
    function showArticle(length){
        for(let index=0;index<length;index++){
            let article='<div class="article"><img src="'+articleData[index].image+'" alt=""><div class="text"><p>'+articleData[index].title+'</p><div class="info"><img src="'+articleData[index].img+'" alt=""><span>'+articleData[index].name+'</span><span>'+articleData[index].date+'</span> <div class="praise"><span><em class="iconfont icon-zhuanfa"></em>'+articleData[index].forwarding+'</span>|<span><em class="iconfont icon-xinxi"></em>'+articleData[index].comments+'</span>|<span><em class="iconfont icon-zan addP"></em>'+articleData[index].praise+'</span> </div></div></div> </div>';
            $("#articles").append(article);
        }
    }
    showArticle(2);
    let i=1;
    // 一次性加载4篇
    let a=2;
    let flag=true;
    $(document).scroll(function(){
        // 可视区域的高度
        let cHeight=document.documentElement.clientHeight;
        // 滚动高度
        let sTop=$(document).scrollTop();
        let timer;
        if(i<articleData.length-1 && $(".article").eq(i).offset().top<cHeight+sTop){
            i=i+a;
            // console.log(i);
            $("#articles").append("<div class='weidu'>正在加载中，请稍后</div>");
            timer=setTimeout(function(){
                showArticle(a);
                $(".weidu").remove();
            },1000)
        }
        if(i>=articleData.length && flag){
            clearTimeout(timer);
            flag=false;
            $(".weidu").remove();
            $("#articles").append("<div class='weidu'>没有更多文章了</div>");
        }
    })
    
    // 轮播
    var add=0;
    
    function showLunbo(){
        let lunbo=`
            <div id="carousel">
                <img src="${lunbo_data[0].img1}" class="img1">
                <img src="${lunbo_data[0].img2}" class="img2">
                <img src="${lunbo_data[0].img3}" class="img3">
                <p class="content1">${lunbo_data[0].content1}</p>
                <span class="content1_item">${lunbo_data[0].content1_item}</span>
                <span class="content2_item">${lunbo_data[0].content2_item}</span>
                <span class="content2">${lunbo_data[0].content2}</span>
                <span class="content3">${lunbo_data[0].content3}</span>
            </div>
            `;
        $("#carousels").html(lunbo);
        lunbotime=setInterval(function(){
            add++;
            if(add>=lunbo_data.length){
                add=0;
            }
            let lunbo=`
            <div id="carousel">
                <img src="${lunbo_data[add].img1}" class="img1">
                <img src="${lunbo_data[add].img2}" class="img2">
                <img src="${lunbo_data[add].img3}" class="img3">
                <p class="content1">${lunbo_data[add].content1}</p>
                <span class="content1_item">${lunbo_data[add].content1_item}</span>
                <span class="content2_item">${lunbo_data[add].content2_item}</span>
                <span class="content2">${lunbo_data[add].content2}</span>
                <span class="content3">${lunbo_data[add].content3}</span>
            </div>
            `;
            $("#carousels").html(lunbo);
            
        },2000)
    }
    showLunbo();
})